/**
 * 
 */
package com.wm.service.imp;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.wm.bean.Area;
import com.wm.bean.City;
import com.wm.bean.MenuType;
import com.wm.bean.ResMenu;
import com.wm.comm.Util;
import com.wm.dao.AreaDAO;
import com.wm.dao.CityDAO;
import com.wm.dao.MenuTypeDAO;
import com.wm.dao.ResMenuDAO;
import com.wm.service.AreaService;
import com.wm.service.CityService;
import com.wm.service.ResMenuService;
import com.wm.service.web.PageList;
import com.wm.service.web.Pages;

/**
 * @author zhangbaochao
 *
 */
public class ResMenuServiceImp implements ResMenuService {
	
	private ResMenuDAO resMenuDAO;
	private MenuTypeDAO menuTypeDAO;
	
	public MenuTypeDAO getMenuTypeDAO() {
		return menuTypeDAO;
	}

	public void setMenuTypeDAO(MenuTypeDAO menuTypeDAO) {
		this.menuTypeDAO = menuTypeDAO;
	}

	public ResMenuDAO getResMenuDAO() {
		return resMenuDAO;
	}

	public void setResMenuDAO(ResMenuDAO resMenuDAO) {
		this.resMenuDAO = resMenuDAO;
	}
	
	/**
	 * 添加
	 * @param r
	 * @return
	 */
	public ResMenu saveResMenu(ResMenu r){
		return this.getResMenuDAO().saveResMenu(r);
	}
	
	/**
	 * 修改
	 * @param r
	 * @return
	 */
	public ResMenu updateResMenu(ResMenu r){
		return this.getResMenuDAO().updateResMenu(r);
	}
	
	/**
	 * 删除
	 * @param r
	 */
	public void removeResMenuById(long id){
		ResMenu r = this.getResMenuDAO().findResMenuById(id);
		if(r == null){
			
		}else{
			this.getResMenuDAO().removeResMenu(r);
		}
	}
	
	/**
	 * 根据ID查询
	 * @param id
	 * @return
	 */
	public ResMenu findResMenuById(long id){
		return this.getResMenuDAO().findResMenuById(id);
	}
	
	/**
	 * 根据参数获取Area对象列表
	 * 
	 * @param menuName
	 * @param typeId
	 * @param isShow
	 * @param orderby
	 * @param ascOrDesc
	 * @param pages
	 * @return PageList
	 * 			PageList
	 */
	public PageList findResMenus(long resId,String menuName,long typeId,int price,int isShow,String orderby,int ascOrDesc,Pages pages){
		PageList pl = new PageList();
        if (pages.getTotalNum() == -1) {
            pages.setTotalNum(this.getResMenuDAO().getResMenuNum(resId,menuName, typeId,price, isShow));
        }
        pages.executeCount();
        if(pages.getTotalNum() == 0){
        	pl.setObjectList(null);
        	pl.setPages(pages);
        	return pl;
        }
        List l = this.getResMenuDAO().findResMenus(resId,menuName, typeId,price, isShow, orderby, ascOrDesc, pages.getSpage(), pages.getPerPageNum());
        if(l == null || l.isEmpty()){
	   		 pl.setObjectList(null);
	   	     pl.setPages(pages);
	   		 return pl;
		}else{
			pl.setObjectList(l);
	        pl.setPages(pages);
	        return pl;
		} 
	}
	
	/**
	 * 根据店铺Id以及菜单分类表查询菜单
	 * @param resId
	 * @return
	 */
	public List findResMenuResMenuTypeByResId(long resId){
		List l = new ArrayList();
		List menuTypeList = this.getMenuTypeDAO().findMenuTypeByIsShow(1, "id", 0);
		if(menuTypeList!=null){
			for(int i=0;i<menuTypeList.size();i++){
				MenuType menuType = (MenuType)menuTypeList.get(i);
				List resMenuList = this.getResMenuDAO().findMenuByResIdTypeIdIsShow(resId, menuType.getId(), 1);
				if(resMenuList!=null &&resMenuList.size()>0){
					for(int j=0;j<resMenuList.size();j++){
						ResMenu rm = (ResMenu)resMenuList.get(j);
						rm.setPriceShow(Util.getPriceShow(rm.getPrice()));
						rm.setDiscountShow(Util.getPriceShow(rm.getDiscount()));
					}
					menuType.setResMenuList(resMenuList);
					l.add(menuType);
				}
			}
		}
		return l;
	}
	
	public static void main(String[] args) {
		long a = 105/10;
		long b = 105%10;
		System.out.println(a+"."+b);
	}
}
